package api;

import conf.App;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import utils.HttpClientUtil;
import utils.ResponseData;

import java.util.HashMap;
import java.util.Map;

public class LoginApi {
    private static final Logger log = LoggerFactory.getLogger(LoginApi.class);
    private static final String loginUrl = App.BASE_URL + "/system/public/verifyLogin";

    /**
     * 登录
     *
     * @param username 用户名
     * @param password 密码
     * @param code     验证码
     * @return 构建之后的响应数据
     */
    public ResponseData login(String username, String password, String code) throws Exception {
        log.info("param username={} password={} code={}", username, password, code);

        Map<String, String> formParams = new HashMap<>();
        if (username != null) {
            formParams.put("username", username);
        }
        if (password != null) {
            formParams.put("password", password);
        }
        if (code != null) {
            formParams.put("valicode", code);
        }
        return HttpClientUtil.post_form(loginUrl, formParams);
    }

}
